home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / progem.arc / gem4.asc < prev    next >
Text File  |  1987-10-10  |  18KB  |  336 lines

  1.                        **Professional GEM**
  2.                            by Tim Oren
  3.  
  4.                              11/7/85
  5.  
  6.  
  7.    Welcome to the fourth installment of ST PRO GEM.  We are about to
  8. delve into the mysteries of GEM resource structure, and then use this
  9. knowledge to create some useful utilities for handling dialogs.  As
  10. with the past columns, there is once again a download file.  You will
  11. find it under the name GEMCL4.C in the ATARI 16-bit Forum (GO PCS-58).
  12.  
  13.    The first and largest part of the download contains a C image of a
  14. sample resource file.  To create this listing, I used the GEM
  15. Resource  Construction Set to create a dummy resource with three
  16. dialogs including examples of all object types, then enabled the C
  17. output option and saved  the resource.  If you have access to a copy
  18. of RCS, I suggest that you  create your own listing in order to get a
  19. feel for the results.  Then, using  either listing as a roadmap to
  20. the resource, you can follow along as  we enter...
  21.  
  22.    A MAZE OF TWISTY LITTLE PASSAGES.  While a GEM resource is loaded
  23. as a block of binary information, it is actually composed of a number
  24. of different data structures.  These structures are linked together
  25. in a rather tangled hierarchy.  Our first job is to map this linkage
  26. system.
  27.  
  28.    The topmost structure in a resource file is the resource header.
  29. This is an array of words containing the size and offset within the
  30. resource of the other structures which follow.  This information is
  31. used by  GEM during the resource load process, and you should never
  32. need to access it. (The resource header does not appear in the C
  33. output file; it is generated by the RSCREATE utility if the C file is
  34. used to recreate the resource.)
  35.  
  36.    The next structure of interest is the tree index.  This is an
  37. array of long pointers, each of which addresses the beginning of an
  38. object tree. Again, you wouldn't normally access this structure
  39. directly.  The GEM  rsrc_gaddr call uses it when finding trees'
  40. addresses.  This structure is called "rs_trindex" in the C output.
  41.  
  42.    If you look at the contents of rs_trindex you will notice that the
  43. values are integers, instead of the pointers I described.  What has
  44. happened is that RCS has converted the pointers to indices into the
  45. object array. (If you actually used the C file to recreate the
  46. resource file, then the  pointers would be regenerated by RSCREATE.)
  47.  
  48.  
  49.    Now you can follow the link from rs_trindex to the objects stored
  50. in rs_object.  Take (for instance) the second entry in rs_trindex and
  51. count down that many lines in rs_object.  The following line (object)
  52. should start with a -1.  This indicates that it is the root object of
  53. a tree.  The following objects down to the next root belong to that
  54. tree. We'll pass over the details of inter-object linkage for now,
  55. leaving it for a later column.
  56.  
  57.    There are a number of different fields in an object, but right now
  58. we'll concentrate on two of them: OB_TYPE and OB_SPEC.  The OB_TYPE
  59. is the field which contains mnemonics like G_STRING and G_BOX
  60. indicating the type of the object.  The OB_SPEC is the only field in
  61. each object which  is a LONG - you can tell it by the L after the
  62. number.
  63.  
  64.    What's in OB_SPEC depends on the object type, so we need to talk
  65. about what kinds of objects are available, what you might use them
  66. for, and finally how they use the OB_SPEC field.
  67.  
  68.    The box type objects are G_BOX, G_IBOX, and G_BOXCHAR.  A G_BOX is
  69. an opaque rectangle, with an optional border.  It's used to create a
  70. solid patch of color or pattern on which to place other objects.  For
  71. instance, the background of a dialog is a G_BOX.
  72.  
  73.    A G_IBOX is a hollow box which has only a border.  (If the border
  74. has no thickness, then the box is "invisible", hence the name.)  The
  75. favorite use for IBOXes is to hold radio buttons.  There is also one
  76. neat trick you can play with an IBOX.  If you have more than one
  77. object (say an image and a string) which you would like to have
  78. selected all at once, you can insert them in a dialog, then cover
  79. them with an IBOX. Since the box is transparent, they will show
  80. through.  If you now make the box selectable, clicking on it will
  81. highlight the whole area at once!
  82.  
  83.    The G_BOXCHAR is just like a G_BOX, except that a single character
  84. is drawn in its center.  They are mostly used as "control points":
  85. the FULLER, CLOSER, SIZER, and arrows in GEM windows are BOXCHARs, as
  86. are  the components of the color selection gadgets in the RCS.
  87.  
  88.    The OB_SPEC for box type objects is a packed bit array.  Its
  89. various fields contain the background color and pattern, the border
  90. thickness and color, and the optional character and its color.
  91.  
  92.    The string type objects are G_STRING, G_BUTTON, and G_TITLE.
  93. G_STRINGs (in addition to being a bad pun) are for setting up static
  94. explanatory text within dialogs.  The characters are always written
  95. in the "system font": full size, black, with no special effects.
  96.  
  97.    We have already discussed many of the uses of G_BUTTONs.  They add
  98. a border around the text.  The thickness of a G_BUTTON's border is
  99. determined by what flags are set for the object.  All buttons start
  100. out with a border thickness of one pixel.  One pixel is added if the
  101. EXIT attribute is set, and one more is added if the DEFAULT attribute
  102. is set.
  103.  
  104.    The G_TITLE type is a specially formatted text string used only in
  105. the title bar of menus.  This type is needed to make sure that the
  106. menus redraw correctly.  The Resource Construction Set automatically
  107. handles inserting G_TITLEs, so you will seldom use them directly.
  108.  
  109.    In a resource, the OB_SPEC for all string objects is a long
  110. pointer to a null terminated ASCII string.  The string data in the C
  111. file is shown in the BYTE array rs_strings.  Again you will notice
  112. that  the OB_SPECs in the C file have been converted to indices into
  113. rs_string. To find the string which matches the object, take the
  114. value of OB_SPEC and count down that many lines in rs_strings.  The
  115. next line is the correct string.
  116.  
  117.    The formatted text object types are G_TEXT, G_BOXTEXT, G_FTEXT,
  118. and G_FBOXTEXT.  G_TEXTs are a lot like strings, except that you can
  119. specify a color, different sizes, and a positioning rule for the
  120. text.   Since they require more memory than G_STRINGs, G_TEXTs should
  121. be used  sparingly to draw attention to important information within
  122. a dialog.   G_TEXTs are also useful for automatic centering of dialog
  123. text which is  changed at run-time.  I will describe this technique
  124. in detail later on.
  125.  
  126.    The G_BOXTEXT type adds a solid background and border to the
  127. G_TEXT type.  These objects are occasionally used in place of
  128. G_BUTTONs when their color will draw attention to an important
  129. object.
  130.  
  131.    The G_FTEXT object is an editable text field.  You are able to
  132. specify a constant "template" of characters, a validation field for
  133. those characters which are to be typed in, and an initial value for
  134. the input characters.  You may also select color, size, and
  135. positioning rule for G_FTEXTs.  We'll discuss text editing at length
  136. below.
  137.  
  138.    The G_FBOXTEXT object, as you might suspect, is the same as
  139. G_FTEXT with the addition of background and border.  This type is
  140. seldom used: the extra appearance details distract attention from the
  141. text being edited.
  142.  
  143.    The OB_SPEC for a formatted text object is a pointer to yet
  144. another type of structure: a TEDINFO.  In the C file, you will find
  145. these in rs_tedinfo.  Take the OB_SPEC value from each text type
  146. object and count down that many entries in rs_tedinfo, finding the
  147. matching TEDINFO on the next line.  Each contains pointers to ASCII
  148. strings for the template, validation, and initialization.  You can
  149. find these strings in rs_strings, just as above.
  150.  
  151.    There are also fields for the optional background and border
  152. details, and for the length of the template and text.  As we will see
  153. when discussing  editing, the most important TEDINFO fields are the
  154. TE_PTEXT pointer to  initialized text and the TE_TXTLEN field which
  155. gives its length.
  156.  
  157.    The G_IMAGE object type is the only one of its kind.  A G_IMAGE is
  158. a monochrome bit image.  For examples, see the images within the
  159. various GEM alert boxes.  Note that monochrome does not necessarily
  160. mean black.